<template>
	<view class="content">
		<view class="top"></view>
		<view class="list listBorder clearfix">
			<input type="text" placeholder="请输入昵称" v-model="nickName" class="input" :focus='setFocus' />
			<view class="delect" @tap="delectName" v-if="nickName!=''">
				<img src="https://cdn.yueyangshuyuan.com/delect.png" />
			</view>
		</view>
		<view class="saveBtn" @tap="saveName">保存</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickName:"",
				setFocus:true,
				dataJSON:{}
			}
		},
		created() {
		   this.$api.getUser({}).then(json=>{
			   // console.log(json.data,"8888888");
			   // this.sex=json.data.sex==null?"":json.data.sex;
			   // this.headImgUrl=json.data.headImgUrl==null?'https://cdn.yueyangshuyuan.com/personImg.png':json.data.headImgUrl;
			   this.nickName=json.data.nickName;
			   this.dataJSON=json.data;
			   
		   });
		},
		methods:{
			//删除昵称
            delectName(){
				this.nickName="";
			},
			saveName(){
				// console.log(this.nickName,1111111);
				let data=this.dataJSON.headImgUrl.split("://")[1];
				let data1=data.split("/")[1];
				// this.dataJSON.sex==null?'':this.dataJSON.sex="";;
				if(this.dataJSON.sex==null||this.dataJSON.sex=="null"){
					this.dataJSON.sex="";
				}
				// console.log(this.dataJSON.sex,8888)
				// setUser
				this.$api.setUser({
					nickName:this.nickName,
					sex:this.dataJSON.sex,
					headImg:data1
				}).then(json=>{
				    uni.redirectTo({
				        url: '/pages/userData/userData'
				    });
				});
				
			}
		},
	}
</script>

<style lang="scss">
	.clearfix:after {
		clear: both;
		content: ".";
		display: block;
		font-size: 0;
		height: 0;
		line-height: 0;
		visibility: hidden;
	}
	.clearfix {
		clear: both;
		zoom: 1;
	}
	.content {
		padding:0;
		margin:0;
		background: #fff;
	}
	.top {
		border-top: 2upx solid #E2E6EE;
		height:25upx;
		background: #fff;
	}
	.list {
		background: #F1F5F8;
		.input {
			float: left;
			width:606upx;
			outline: none;
			background: none;
			border:none;
			height:100upx;
			background: #F1F5F8;
			padding:20upx 0 20upx 50upx;
			box-sizing: border-box;
		}
		.delect {
			float: left;
			width:144upx;
			height:100upx;
			img {
				display: block;
				width:44upx;
				height:44upx;
				margin-top:33upx;
				margin-left:50upx;
			}
		}
		
	}
    .saveBtn {
			width:520upx;
			height:90upx;
			border: 1px solid #C6C6C6;
			border-radius: 106px;
			margin:300upx 115upx;
			line-height: 90upx;
			text-align: center;
			font-size: 32upx;
			color: #262626;
		}
</style>
